#ifndef _MY_CONFIG_
#define _MY_CONFIG_
#include "Util.hpp"
namespace cloud{
class Config
{
private:
    Config()
    {
        ReadConfigFile();
    }
    static std::mutex _mutex;
    static Config *_instance;
private:
    int _hot_time;
    int _server_port;
    string _download_prefix;
    string _packfile_suffix;
    string _back_dir;
    string _pack_dir;
    string _server_ip;
    string _backup_file;
    bool ReadConfigFile()
    {
        FileUtil fu("./cloud.conf");
        string body;
        if (fu.GetContent(&body) == false)
        {
            cout << "load config file failed" << endl;
            return false;
        }
        Json::Value root;
        if (JsonUtil::UnSerialize(body, &root) == false)
        {
            cout << "parse config file failed" << endl;
            return false;
        }
        _hot_time = root["hot_time"].asInt();
        _server_port = root["server_port"].asInt();
        _download_prefix = root["download_prefix"].asString();
        _packfile_suffix = root["packfile_suffix"].asString();
        _back_dir = root["back_dir"].asString();
        _pack_dir = root["pack_dir"].asString();
        _server_ip = root["server_ip"].asString();
        _backup_file = root["backup_file"].asString();
        return true;
    }

public:
    static Config *GetInstance()
    {
        if (_instance == nullptr)
        {
            _mutex.lock();
            if (_instance == nullptr)
            {
                _instance = new Config();
            }
            _mutex.unlock();
        }
        return _instance;
    }
    int GetHotTime()
    {
        return _hot_time;
    }
    int GetServerPort()
    {
        return _server_port;
    }
    string GetServerIp()
    {
        return _server_ip;
    }
    string GetDownloadPrefix()
    {
        return _download_prefix;
    }
    string GetPackFileSuffix()
    {
        return  _packfile_suffix;
    }
    string GetPackDir()
    {
        return _pack_dir;
    }
    string GetPackFileSuffix()
    {
        return _packfile_suffix;
    }
    string GetBackDir()
    {
        return _back_dir;
    }
    string GetBackupFile()
    {
        return _backup_file;
    }
};
};
#endif